﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using MvcShop.Extensions;
using System.Security.Permissions;

namespace MvcShop.MVC.Filters
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]  //标记用法声明
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] //标记声明安全性
    class CompressAttribute:ActionFilterAttribute
    {
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            // 只对没有异常抛出的请求处理进行压缩
            if ((filterContext.Exception == null) || ((filterContext.Exception != null) && filterContext.ExceptionHandled))
            {
                filterContext.HttpContext.CompressResponse();
            }

            base.OnResultExecuted(filterContext);
        }
    }
}
